Skip to main content

安装MySQL

1. 安装包下载

wget https://redoop-public-1.oss-cn-beijing.aliyuncs.com/redoop/9.1/x86/share/mysql/mysql-community-common-5.7.16-1.el7.x86_64.rpm
wget https://redoop-public-1.oss-cn-beijing.aliyuncs.com/redoop/9.1/x86/share/mysql/mysql-community-libs-5.7.16-1.el7.x86_64.rpm
wget https://redoop-public-1.oss-cn-beijing.aliyuncs.com/redoop/9.1/x86/share/mysql/mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm
wget https://redoop-public-1.oss-cn-beijing.aliyuncs.com/redoop/9.1/x86/share/mysql/mysql-community-client-5.7.16-1.el7.x86_64.rpm
wget https://redoop-public-1.oss-cn-beijing.aliyuncs.com/redoop/9.1/x86/share/mysql/mysql-community-server-5.7.16-1.el7.x86_64.rpm

2 安装MySQL所需依赖项

# 1.查询安装了是否mariadb
rpm -qa | grep mariadb

# 2.卸载mariadb
sudo rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps

# 3.安装mysql依赖包
yum install libaio-devel.x86_64
yum install net-tools
yum install numactl-libs.x86_64

sudo rpm -ivh mysql-community-common-5.7.16-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-libs-5.7.16-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm

3 安装MySQL-client、server

sudo rpm -ivh mysql-community-client-5.7.16-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm

4 启动MySQL

  • 启动MySQL
sudo systemctl start mysqld
  • 查看MySQL密码
sudo cat /var/log/mysqld.log | grep password

5 配置MySQL

+ 配置只要是root用户 + 密码,在任何主机上都能登录MySQL数据库。
+ 用刚刚查到的密码进入MySQL(如果报错,给密码加单引号)
mysql -uroot -p'password'

设置复杂密码(由于MySQL密码策略,此密码必须足够复杂)

set password=password("Qs23=zs32");

更改MySQL密码策略

set global validate_password_length=4; 
set global validate_password_policy=0;

设置简单好记的密码

set password=password("123456");

进入MySQL库

use mysql;

查询user表

select user, host from user;

修改user表,把Host表内容修改为%

update user set host="%" where user="root";

注意,修改最大连接数

set GLOBAL max_connections=1024; 
show variables like '%max_connections%';
show status like 'Threads%';

刷新

flush privileges;

退出

quit;